#include <bits/stdc++.h>
using namespace std;
int prefa[5001], prefb[5001];
int main()
{
string s;
cin >> s;
int num = 0;
int n = s.size();
for(int i = 1; i <= n; i++)
{
prefa[i] = prefa[i - 1] + (s[i - 1] == 'a');
prefb[i] = prefb[i - 1] + (s[i - 1] == 'b');
}
int maxim = 0;
for(int i = 0; i <= n; i++)
{
for(int j = i; j <= n; j++)
{
maxim = max(maxim, prefa[i] + (prefb[j] - prefb[i]) + (prefa[n] - prefa[j]));
}
}
cout << maxim;
return 0;
}
1478A - Nezzar and Colorful Balls | 1581B - Diameter of Graph |
404A - Valera and X | 908A - New Year and Counting Cards |
146A - Lucky Ticket | 1594C - Make Them Equal |
1676A - Lucky | 1700B - Palindromic Numbers |
702C - Cellular Network | 1672C - Unequal Array |
1706C - Qpwoeirut And The City | 1697A - Parkway Walk |
1505B - DMCA | 478B - Random Teams |
1705C - Mark and His Unfinished Essay | 1401C - Mere Array |
1613B - Absent Remainder | 1536B - Prinzessin der Verurteilung |
1699B - Almost Ternary Matrix | 1545A - AquaMoon and Strange Sort |
538B - Quasi Binary | 424A - Squats |
1703A - YES or YES | 494A - Treasure |
48B - Land Lot | 835A - Key races |
1622C - Set or Decrease | 1682A - Palindromic Indices |
903C - Boxes Packing | 887A - Div 64 |